﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:System_Windows_Controls_DataVisualization_Charting_Primitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    x:Class="StockTraderRI.Modules.Market.TrendLine.TrendLineView"
    mc:Ignorable="d" BorderThickness="0,0,0,0"
    Height="190">
    <UserControl.Resources>
        <!-- By convention every view inside the ResearchControl (ResearchRegion) has to declare 
             a DataTemplate with the "HeaderIcon" key which defines the icon on the Header -->
        <DataTemplate x:Key="HeaderIcon">
            <Grid Margin="15,5,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" Height="13" Width="16">
                <Path Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M403.16667,431.66667 L403.16667,448.33299 417.00699,448.33299 417.00699,432.24967"/>
                <Path HorizontalAlignment="Left" Margin="4.503,6,0,0" Width="2" Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M403.16667,431.66667 L403.16667,448.33299"/>
                <Path HorizontalAlignment="Right" Margin="0,2,4.751,0" Width="2" Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M403.16667,431.66667 L403.16667,448.33299"/>
            </Grid>
        </DataTemplate>
        <ControlTemplate x:Key="TrendLineEmptyLegendStyle" TargetType="toolkit:Legend">
            <Grid/>
        </ControlTemplate>
        <Style x:Key="TrendLineChartStyle" TargetType="charting:Chart">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="IsTabStop" Value="False"/>
            <!--<Setter Property="Padding" Value="10"/>-->
            <Setter Property="Palette">
                <Setter.Value>
                    <toolkit:ResourceDictionaryCollection>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB9D6F7"/>
                                <GradientStop Color="#FF284B70" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFFBB7B5"/>
                                <GradientStop Color="#FF702828" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB8C0AC"/>
                                <GradientStop Color="#FF5F7143" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFFDE79C"/>
                                <GradientStop Color="#FFF6BC0C" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFA9A3BD"/>
                                <GradientStop Color="#FF382C6C" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB1A1B1"/>
                                <GradientStop Color="#FF50224F" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FF9DC2B3"/>
                                <GradientStop Color="#FF1D7554" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFB5B5B5"/>
                                <GradientStop Color="#FF4C4C4C" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FF98C1DC"/>
                                <GradientStop Color="#FF0271AE" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFC1C0AE"/>
                                <GradientStop Color="#FF706E41" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFADBDC0"/>
                                <GradientStop Color="#FF446A73" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FF2F8CE2"/>
                                <GradientStop Color="#FF0C3E69" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFDCDCDC"/>
                                <GradientStop Color="#FF757575" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFF4F4F4"/>
                                <GradientStop Color="#FFB7B7B7" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                        <ResourceDictionary>
                            <RadialGradientBrush x:Key="Background" Center="0.075,0.015" GradientOrigin="-0.1,-0.1" RadiusY="0.9" RadiusX="1.05">
                                <GradientStop Color="#FFF4F4F4"/>
                                <GradientStop Color="#FFA3A3A3" Offset="1"/>
                            </RadialGradientBrush>
                            <Style x:Key="DataPointStyle" TargetType="Control">
                                <Setter Property="Background" Value="{StaticResource Background}"/>
                            </Style>
                            <Style x:Key="DataShapeStyle" TargetType="Shape">
                                <Setter Property="Stroke" Value="{StaticResource Background}"/>
                                <Setter Property="StrokeThickness" Value="2"/>
                                <Setter Property="StrokeMiterLimit" Value="1"/>
                                <Setter Property="Fill" Value="{StaticResource Background}"/>
                            </Style>
                        </ResourceDictionary>
                    </toolkit:ResourceDictionaryCollection>
                </Setter.Value>
            </Setter>
            <Setter Property="TitleStyle">
                <Setter.Value>
                    <Style TargetType="toolkit:Title">
                        <Setter Property="FontSize" Value="16"/>
                        <Setter Property="HorizontalAlignment" Value="Center"/>
                        <Setter Property="Margin" Value="0,10,0,10"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="LegendStyle">
                <Setter.Value>
                    <Style TargetType="toolkit:Legend">
                        <Setter Property="Margin" Value="15,0,15,0"/>
                        <Setter Property="VerticalAlignment" Value="Center"/>
                        <Setter Property="BorderBrush" Value="#FFDBDBDB"/>
                        <Setter Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush EndPoint="0.442,0.005" StartPoint="0.558,0.995">
                                    <GradientStop Color="#FFDBDBDB"/>
                                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="ChartAreaStyle">
                <Setter.Value>
                    <Style TargetType="Panel">
                        <Setter Property="MinWidth" Value="100"/>
                        <Setter Property="MinHeight" Value="75"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="PlotAreaStyle">
                <Setter.Value>
                    <Style TargetType="Grid">
                        <Setter Property="Background" Value="{x:Null}">
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:Chart">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <toolkit:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}"/>
                                <Grid Margin="0,15,0,15" Grid.Row="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <toolkit:Legend x:Name="Legend" Grid.Column="1" Header="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}" Template="{StaticResource TrendLineEmptyLegendStyle}"/>
                                    <System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
                                        <Grid Style="{TemplateBinding PlotAreaStyle}" Canvas.ZIndex="-1"/>
                                        <Border BorderThickness="1" Canvas.ZIndex="10"/>
                                    </System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel>
                                </Grid>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Border BorderThickness="0,0,0,1" BorderBrush="#FFFFFFFF" Padding="10,10,10,10">
        <Grid x:Name="MainGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,0">
                <TextBlock Text="{Binding TickerSymbol}" Style="{StaticResource TextBlockSectionTitle}" />
                <TextBlock Text=" HISTORICAL DATA" Style="{StaticResource TextBlockSectionTitle}" AutomationProperties.AutomationId="HistoricalDataTextBlock" />
            </StackPanel>
            <Border Grid.Row="1">
                <charting:Chart Grid.Row="1" x:Name="lineChart" 
            		Title="{Binding TickerSymbol}" 
            		Height="170" 
            		BorderThickness="0" 
            		FontFamily="Arial" 
            		FontSize="10" 
            		Foreground="#FF313131" Style="{StaticResource TrendLineChartStyle}">
                    <charting:Chart.Axes>
                        <toolkit:LinearAxis Orientation="Y" Minimum="0" ShowGridLines="True" BorderThickness="1" />
                        <toolkit:DateTimeAxis Orientation="X" ShowGridLines="False" IntervalType="Days" MaxWidth="150" BorderThickness="1" />
                    </charting:Chart.Axes>

                    <toolkit:LineSeries
            			ItemsSource="{Binding HistoryCollection}"
            			DependentValueBinding="{Binding Value}"
            			IndependentValueBinding="{Binding DateTimeMarker}"                            
                            />
                </charting:Chart>
            </Border>
        </Grid>
    </Border>
</UserControl>
